var mongoose = require("mongoose");
mongoose.connect("mongodb://127.0.0.1/test", { useUnifiedTopology: true });
mongoose.connection.once("open", function() {
        console.log("链接成功");
    })
    //将mongose.Schema赋值给一个变量Schema
var Schema = mongoose.Schema;
//创建一个Schema对象
var stuSchme = new Schema({
    name: String,
    age: Number,
    gender: {
        type: String,
        default: "female"
    },
    address: String
});
/*
    Document和集合中的文档一一对应，Document是Model的实例
        通过Model查询到的结果都是Document
*/
//创建一个Document
var stu = new stuSchme({
    name: "ccc",
    age: 48,
    gender: "male",
    address: "hebei"
});
/*
    document的方法
        Model#save([options],[fn])
        用来保存，需要通过文档调用
*/
stu.save(function(err) {
    if (!err) {
        console.log("保存成功")
    }
})